<?php

class Achievement {
	
	public $id;
	public $topscorer = 0;
	public $doubledouble = 0;
	public $trippledouble = 0;
	public $quadrupledouble = 0;
	public $gamemvp = 0;
	public $roundmvp = 0;
	
	// constructor
	
	public function __construct($p, $m) {
		$this->id = 0;
		if ($p && $m) {
			$this->getMatchAchievements($p, $m);
		}
	}
	
	// functions
	
	private function getMatchAchievements($p, $m) {
		$player = new Player($p);
		$match = new Match($m);
		
		if ($match->odigrana) {
		
			$player->getStats($match->id);
			
			$match->domacin->getRoster();
			$match->gost->getRoster();
			
			foreach($match->domacin->roster as $igrac) {
				$igrac->getStats($match->id);
			}
			foreach($match->gost->roster as $igrac) {
				$igrac->getStats($match->id);
			}
			
			$match->domacin->stats = $match->domacin->getMatchStats($match->id);
			$match->gost->stats = $match->gost->getMatchStats($match->id);
				
			$doubles = 0;
			if ($player->stats[$match->id]->pts > 9) $doubles++;
			if ($player->stats[$match->id]->totalRbd > 9) $doubles++;
			if ($player->stats[$match->id]->blk > 9) $doubles++;
			if ($player->stats[$match->id]->ast > 9) $doubles++;
			if ($player->stats[$match->id]->stl > 9) $doubles++;
			
			if ($doubles >= 4) $this->quadrupledouble++;
			if ($doubles == 3) $this->trippledouble++;
			if ($doubles == 2) $this->doubledouble++;
			
			if ($player->id == $match->findMVP()->id) $this->gamemvp++;
			if ($player->id == $match->findTopScorer()->id) $this->topscorer++;
		}
	}
			
} // end of class Achievement


?>